package com.combetter.changxing.viewmodel.base;

import android.app.Application;
import android.databinding.ObservableBoolean;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;

/**
 * Created by Mark.fan on 2018/5/10.
 */

public abstract class BaseRefreshViewModel<T>  extends BaseRecyclerViewModel<T> {
    //刷新状态
    private final ObservableBoolean refreshing = new ObservableBoolean(false);

    public BaseRefreshViewModel(@NonNull Application application, int itemLayout) {
        super(application, itemLayout);
    }

    private SwipeRefreshLayout.OnRefreshListener onRefreshListener = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            BaseRefreshViewModel.this.onRefresh();
        }
    };

    public SwipeRefreshLayout.OnRefreshListener getOnRefreshListener() {
        return onRefreshListener;
    }

    /**
     * 父类重写该方法处理列表下拉逻辑
     */
    public abstract void onRefresh();

    /**
     * SwipeRefreshLayout 双向绑定
     * @param isRefreshing
     */
    public void setRefreshing(Boolean isRefreshing){
        refreshing.set(isRefreshing);
    }

    /**
     * SwipeRefreshLayout 双向绑定
     */
    public ObservableBoolean getRefreshing() {
        return refreshing;
    }
}
